// 输出第二大的值及其坐标
function getSecondMax2(arr) {
    // 双指针
    let resArr = new Array(2).fill(0)
    let max = new Array(2).fill(0)
    let second = new Array(2).fill(0)
    if (arr.length === 1) return -1
    if (arr.length === 2) {
        if (arr[1] > arr[0]) {
            resArr[0] = 0
            resArr[1] = arr[0]

        }
        else {
            resArr[0] = 1
            resArr[1] = arr[1]
        }
        return resArr
    }
    if (arr[0] > arr[1]) {
        max[0] = 0
        max[1] = arr[0]
        second[0] = 1
        second[1] = arr[1]
    }
    else {
        max[0] = 1
        max[1] = arr[1]
        second[0] = 0
        second[1] = arr[0]
    }
    for (let i = 2; i < arr.length; i ++) {
        // 无论这个数是多少 只要大于second即可替换
        if (arr[i] > second[1]) {
            // 再在里面判断是否是最大的
            if (arr[i] > max[1]) {
                second[0] = max[0]
                second[1] = max[1]
                max[0] = i
                max[1] = arr[i]
            }
            else {
                second[0] = i
                second[1] = arr[i]
            }

        }
    }
    return second
}

let Arr = [1,5,2,7,33,10,22]
console.log(getSecondMax2(Arr));
